home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / clang / cweb31.zip / CTANGLE.C < prev    next >
C/C++ Source or Header  |  1993-11-08  |  30KB  |  1,551 lines

  1. /*1:*/
  2. #line 61 "ctangle.w"
  3.  
  4. /*6:*/
  5. #line 35 "common.h"
  6.  
  7. #include <stdio.h>
  8.  
  9. /*:6*//*62:*/
  10. #line 873 "ctangle.w"
  11.  
  12. #include <ctype.h> 
  13. #include <stdlib.h> 
  14.  
  15. /*:62*/
  16. #line 62 "ctangle.w"
  17.  
  18. #define banner "This is CTANGLE (Version 3.1)\n" \
  19.  
  20. #define max_bytes 90000 \
  21.  
  22. #define max_toks 270000
  23. #define max_names 4000 \
  24.  
  25. #define max_texts 2500
  26. #define hash_size 353
  27. #define longest_name 1000
  28. #define stack_size 50
  29. #define buf_size 100 \
  30.  
  31. #define ctangle 0
  32. #define cweave 1 \
  33.  
  34. #define and_and 04
  35. #define lt_lt 020
  36. #define gt_gt 021
  37. #define plus_plus 013
  38. #define minus_minus 01
  39. #define minus_gt 031
  40. #define not_eq 032
  41. #define lt_eq 034
  42. #define gt_eq 035
  43. #define eq_eq 036
  44. #define or_or 037
  45. #define dot_dot_dot 016
  46. #define colon_colon 06
  47. #define period_ast 026
  48. #define minus_gt_ast 027 \
  49.  
  50. #define xisalpha(c)(isalpha(c)&&((eight_bits)c<0200))
  51. #define xisdigit(c)(isdigit(c)&&((eight_bits)c<0200))
  52. #define xisspace(c)(isspace(c)&&((eight_bits)c<0200))
  53. #define xislower(c)(islower(c)&&((eight_bits)c<0200))
  54. #define xisupper(c)(isupper(c)&&((eight_bits)c<0200))
  55. #define xisxdigit(c)(isxdigit(c)&&((eight_bits)c<0200)) \
  56.  
  57. #define length(c)(c+1)->byte_start-(c)->byte_start
  58. #define print_id(c)term_write((c)->byte_start,length((c)))
  59. #define llink link
  60. #define rlink dummy.Rlink
  61. #define root name_dir->rlink \
  62.  
  63. #define chunk_marker 0 \
  64.  
  65. #define spotless 0
  66. #define harmless_message 1
  67. #define error_message 2
  68. #define fatal_message 3
  69. #define mark_harmless {if(history==spotless)history= harmless_message;}
  70. #define mark_error history= error_message
  71. #define confusion(s)fatal("! This can't happen: ",s) \
  72.  
  73. #define max_file_name_length 60
  74. #define cur_file file[include_depth]
  75. #define cur_file_name file_name[include_depth]
  76. #define web_file_name file_name[0]
  77. #define cur_line line[include_depth] \
  78.  
  79. #define show_banner flags['b']
  80. #define show_progress flags['p']
  81. #define show_happiness flags['h'] \
  82.  
  83. #define update_terminal fflush(stdout)
  84. #define new_line putchar('\n')
  85. #define putxchar putchar
  86. #define term_write(a,b)fflush(stdout),fwrite(a,sizeof(char),b,stdout)
  87. #define C_printf(c,a)fprintf(C_file,c,a)
  88. #define C_putc(c)putc(c,C_file) \
  89.  
  90. #define equiv equiv_or_xref \
  91.  
  92. #define section_flag max_texts \
  93.  
  94. #define string 02
  95. #define join 0177
  96. #define output_defs_flag (2*024000-1) \
  97.  
  98. #define cur_end cur_state.end_field
  99. #define cur_byte cur_state.byte_field
  100. #define cur_name cur_state.name_field
  101. #define cur_repl cur_state.repl_field
  102. #define cur_section cur_state.section_field \
  103.  
  104. #define section_number 0201
  105. #define identifier 0202 \
  106.  
  107. #define normal 0
  108. #define num_or_id 1
  109. #define unbreakable 3
  110. #define verbatim 4 \
  111.  
  112. #define max_files 256
  113. #define translit_length 10 \
  114.  
  115. #define ignore 0
  116. #define ord 0302
  117. #define control_text 0303
  118. #define translit_code 0304
  119. #define output_defs_code 0305
  120. #define format_code 0306
  121. #define definition 0307
  122. #define begin_C 0310
  123. #define section_name 0311
  124. #define new_section 0312 \
  125.  
  126. #define constant 03 \
  127.  
  128. #define isxalpha(c)((c)=='_')
  129. #define ishigh(c)((unsigned char)(c)>0177) \
  130.  \
  131.  
  132. #define compress(c)if(loc++<=limit)return(c) \
  133.  
  134. #define macro 0
  135. #define app_repl(c){if(tok_ptr==tok_mem_end)overflow("token");*tok_ptr++= c;} \
  136.  
  137.  
  138. #line 63 "ctangle.w"
  139.  
  140. /*5:*/
  141. #line 29 "common.h"
  142.  
  143. typedef short boolean;
  144. typedef char unsigned eight_bits;
  145. extern boolean program;
  146. extern int phase;
  147.  
  148. /*:5*//*7:*/
  149. #line 57 "common.h"
  150.  
  151. char section_text[longest_name+1];
  152. char*section_text_end= section_text+longest_name;
  153. char*id_first;
  154. char*id_loc;
  155.  
  156. /*:7*//*8:*/
  157. #line 72 "common.h"
  158.  
  159. extern char buffer[];
  160. extern char*buffer_end;
  161. extern char*loc;
  162. extern char*limit;
  163.  
  164. /*:8*//*9:*/
  165. #line 87 "common.h"
  166.  
  167. typedef struct name_info{
  168. char*byte_start;
  169. struct name_info*link;
  170. union{
  171. struct name_info*Rlink;
  172.  
  173. char Ilk;
  174. }dummy;
  175. char*equiv_or_xref;
  176. }name_info;
  177. typedef name_info*name_pointer;
  178. typedef name_pointer*hash_pointer;
  179. extern char byte_mem[];
  180. extern char*byte_mem_end;
  181. extern name_info name_dir[];
  182. extern name_pointer name_dir_end;
  183. extern name_pointer name_ptr;
  184. extern char*byte_ptr;
  185. extern name_pointer hash[];
  186. extern hash_pointer hash_end;
  187. extern hash_pointer h;
  188. extern name_pointer id_lookup();
  189. extern name_pointer section_lookup();
  190. extern void print_section_name(),sprint_section_name();
  191.  
  192. /*:9*//*10:*/
  193. #line 122 "common.h"
  194.  
  195. extern history;
  196. extern err_print();
  197. extern wrap_up();
  198. extern void fatal();
  199. extern void overflow();
  200.  
  201. /*:10*//*11:*/
  202. #line 137 "common.h"
  203.  
  204. extern include_depth;
  205. extern FILE*file[];
  206. extern FILE*change_file;
  207. extern char C_file_name[];
  208. extern char tex_file_name[];
  209. extern char idx_file_name[];
  210. extern char scn_file_name[];
  211. extern char file_name[][max_file_name_length];
  212.  
  213. extern char change_file_name[];
  214. extern line[];
  215. extern change_line;
  216. extern boolean input_has_ended;
  217. extern boolean changing;
  218. extern boolean web_file_open;
  219. extern reset_input();
  220. extern get_line();
  221. extern check_complete();
  222.  
  223. /*:11*//*12:*/
  224. #line 158 "common.h"
  225.  
  226. typedef unsigned short sixteen_bits;
  227. extern sixteen_bits section_count;
  228. extern boolean changed_section[];
  229. extern boolean change_pending;
  230. extern boolean print_where;
  231.  
  232. /*:12*//*13:*/
  233. #line 170 "common.h"
  234.  
  235. extern int argc;
  236. extern char**argv;
  237. extern boolean flags[];
  238.  
  239. /*:13*//*14:*/
  240. #line 182 "common.h"
  241.  
  242. extern FILE*C_file;
  243. extern FILE*tex_file;
  244. extern FILE*idx_file;
  245. extern FILE*scn_file;
  246. extern FILE*active_file;
  247.  
  248. /*:14*//*15:*/
  249. #line 191 "common.h"
  250.  
  251. extern void common_init();
  252. #line 125 "ctangle.w"
  253.  
  254. /*:15*/
  255. #line 64 "ctangle.w"
  256.  
  257. /*16:*/
  258. #line 149 "ctangle.w"
  259.  
  260. typedef struct{
  261. eight_bits*tok_start;
  262. sixteen_bits text_link;
  263. }text;
  264. typedef text*text_pointer;
  265.  
  266. /*:16*//*27:*/
  267. #line 293 "ctangle.w"
  268.  
  269. typedef struct{
  270. eight_bits*end_field;
  271. eight_bits*byte_field;
  272. name_pointer name_field;
  273. text_pointer repl_field;
  274. sixteen_bits section_field;
  275. }output_state;
  276. typedef output_state*stack_pointer;
  277.  
  278. /*:27*/
  279. #line 65 "ctangle.w"
  280.  
  281. /*17:*/
  282. #line 156 "ctangle.w"
  283.  
  284. text text_info[max_texts];
  285. text_pointer text_info_end= text_info+max_texts-1;
  286. text_pointer text_ptr;
  287. eight_bits tok_mem[max_toks];
  288. eight_bits*tok_mem_end= tok_mem+max_toks-1;
  289. eight_bits*tok_ptr;
  290.  
  291. /*:17*//*23:*/
  292. #line 224 "ctangle.w"
  293.  
  294. text_pointer last_unnamed;
  295.  
  296. /*:23*//*28:*/
  297. #line 309 "ctangle.w"
  298.  
  299. output_state cur_state;
  300.  
  301. output_state stack[stack_size+1];
  302. stack_pointer stack_ptr;
  303. stack_pointer stack_end= stack+stack_size;
  304.  
  305. /*:28*//*32:*/
  306. #line 381 "ctangle.w"
  307.  
  308. int cur_val;
  309.  
  310. /*:32*//*36:*/
  311. #line 467 "ctangle.w"
  312.  
  313. eight_bits out_state;
  314. boolean protect;
  315.  
  316. /*:36*//*38:*/
  317. #line 496 "ctangle.w"
  318.  
  319. name_pointer output_files[max_files];
  320. name_pointer*cur_out_file,*end_output_files,*an_output_file;
  321. char cur_section_name_char;
  322. char output_file_name[longest_name];
  323.  
  324. /*:38*//*45:*/
  325. #line 592 "ctangle.w"
  326.  
  327. boolean output_defs_seen= 0;
  328.  
  329. /*:45*//*51:*/
  330. #line 699 "ctangle.w"
  331.  
  332. char translit[128][translit_length];
  333.  
  334. /*:51*//*56:*/
  335. #line 775 "ctangle.w"
  336.  
  337. eight_bits ccode[256];
  338.  
  339. /*:56*//*59:*/
  340. #line 831 "ctangle.w"
  341.  
  342. boolean comment_continues= 0;
  343.  
  344. /*:59*//*61:*/
  345. #line 870 "ctangle.w"
  346.  
  347. name_pointer cur_section_name;
  348.  
  349. /*:61*//*75:*/
  350. #line 1180 "ctangle.w"
  351.  
  352. text_pointer cur_text;
  353. eight_bits next_control;
  354.  
  355. /*:75*//*82:*/
  356. #line 1327 "ctangle.w"
  357.  
  358. extern sixteen_bits section_count;
  359.  
  360. /*:82*/
  361. #line 66 "ctangle.w"
  362.  
  363. /*2:*/
  364. #line 74 "ctangle.w"
  365.  
  366. extern int strlen();
  367. extern int strcmp();
  368. extern char*strcpy();
  369. extern int strncmp();
  370. extern char*strncpy();
  371.  
  372. /*:2*//*41:*/
  373. #line 526 "ctangle.w"
  374.  
  375. void phase_two();
  376.  
  377. /*:41*//*46:*/
  378. #line 595 "ctangle.w"
  379.  
  380. void output_defs();
  381.  
  382. /*:46*//*48:*/
  383. #line 641 "ctangle.w"
  384.  
  385. void out_char();
  386.  
  387. /*:48*//*90:*/
  388. #line 1433 "ctangle.w"
  389.  
  390. void phase_one();
  391.  
  392. /*:90*//*92:*/
  393. #line 1451 "ctangle.w"
  394.  
  395. void skip_limbo();
  396.  
  397. /*:92*/
  398. #line 67 "ctangle.w"
  399.  
  400.  
  401. /*:1*//*3:*/
  402. #line 88 "ctangle.w"
  403.  
  404. int main(ac,av)
  405. int ac;
  406. char**av;
  407. {
  408. argc= ac;argv= av;
  409. program= ctangle;
  410. /*18:*/
  411. #line 164 "ctangle.w"
  412.  
  413. text_info->tok_start= tok_ptr= tok_mem;
  414. text_ptr= text_info+1;text_ptr->tok_start= tok_mem;
  415.  
  416.  
  417. /*:18*//*20:*/
  418. #line 174 "ctangle.w"
  419.  
  420. name_dir->equiv= (char*)text_info;
  421.  
  422. /*:20*//*24:*/
  423. #line 227 "ctangle.w"
  424. last_unnamed= text_info;text_info->text_link= 0;
  425.  
  426. /*:24*//*39:*/
  427. #line 506 "ctangle.w"
  428.  
  429. cur_out_file= end_output_files= output_files+max_files;
  430.  
  431. /*:39*//*52:*/
  432. #line 702 "ctangle.w"
  433.  
  434. {
  435. int i;
  436. for(i= 0;i<128;i++)sprintf(translit[i],"X%02X",(unsigned)(128+i));
  437. }
  438.  
  439. /*:52*//*57:*/
  440. #line 778 "ctangle.w"
  441. {
  442. int c;
  443. for(c= 0;c<256;c++)ccode[c]= ignore;
  444. ccode[' ']= ccode['\t']= ccode['\n']= ccode['\v']= ccode['\r']= ccode['\f']
  445. = ccode['*']= new_section;
  446. ccode['@']= '@';ccode['=']= string;
  447. ccode['d']= ccode['D']= definition;
  448. ccode['f']= ccode['F']= ccode['s']= ccode['S']= format_code;
  449. ccode['c']= ccode['C']= ccode['p']= ccode['P']= begin_C;
  450. ccode['^']= ccode[':']= ccode['.']= ccode['t']= ccode['T']= 
  451. ccode['q']= ccode['Q']= control_text;
  452. ccode['h']= ccode['H']= output_defs_code;
  453. ccode['l']= ccode['L']= translit_code;
  454. ccode['&']= join;
  455. ccode['<']= ccode['(']= section_name;
  456. ccode['\'']= ord;
  457. }
  458.  
  459. /*:57*//*71:*/
  460. #line 1104 "ctangle.w"
  461. section_text[0]= ' ';
  462.  
  463. /*:71*/
  464. #line 95 "ctangle.w"
  465. ;
  466. common_init();
  467. if(show_banner)printf(banner);
  468. phase_one();
  469. phase_two();
  470. return wrap_up();
  471. }
  472.  
  473. /*:3*//*21:*/
  474. #line 180 "ctangle.w"
  475.  
  476. int names_match(p,first,l)
  477. name_pointer p;
  478. char*first;
  479. int l;
  480. {
  481. if(length(p)!=l)return 0;
  482. return!strncmp(first,p->byte_start,l);
  483. }
  484.  
  485. /*:21*//*22:*/
  486. #line 195 "ctangle.w"
  487.  
  488. void
  489. init_node(node)
  490. name_pointer node;
  491. {
  492. node->equiv= (char*)text_info;
  493. }
  494. void
  495. init_p(){}
  496.  
  497. /*:22*//*26:*/
  498. #line 257 "ctangle.w"
  499.  
  500. void
  501. store_two_bytes(x)
  502. sixteen_bits x;
  503. {
  504. if(tok_ptr+2>tok_mem_end)overflow("token");
  505. *tok_ptr++= x>>8;
  506. *tok_ptr++= x&0377;
  507. }
  508.  
  509. /*:26*//*30:*/
  510. #line 333 "ctangle.w"
  511.  
  512. void
  513. push_level(p)
  514. name_pointer p;
  515. {
  516. if(stack_ptr==stack_end)overflow("stack");
  517. *stack_ptr= cur_state;
  518. stack_ptr++;
  519. if(p!=NULL){
  520. cur_name= p;cur_repl= (text_pointer)p->equiv;
  521. cur_byte= cur_repl->tok_start;cur_end= (cur_repl+1)->tok_start;
  522. cur_section= 0;
  523. }
  524. }
  525.  
  526. /*:30*//*31:*/
  527. #line 352 "ctangle.w"
  528.  
  529. void
  530. pop_level(flag)
  531. int flag;
  532. {
  533. if(flag&&cur_repl->text_link<section_flag){
  534. cur_repl= cur_repl->text_link+text_info;
  535. cur_byte= cur_repl->tok_start;cur_end= (cur_repl+1)->tok_start;
  536. return;
  537. }
  538. stack_ptr--;
  539. if(stack_ptr>stack)cur_state= *stack_ptr;
  540. }
  541.  
  542. /*:31*//*33:*/
  543. #line 388 "ctangle.w"
  544.  
  545. void
  546. get_output()
  547. {
  548. sixteen_bits a;
  549. restart:if(stack_ptr==stack)return;
  550. if(cur_byte==cur_end){
  551. cur_val= -((int)cur_section);
  552. pop_level(1);
  553. if(cur_val==0)goto restart;
  554. out_char(section_number);return;
  555. }
  556. a= *cur_byte++;
  557. if(out_state==verbatim&&a!=string&&a!=constant&&a!='\n')
  558. C_putc(a);
  559. else if(a<0200)out_char(a);
  560. else{
  561. a= (a-0200)*0400+*cur_byte++;
  562. switch(a/024000){
  563. case 0:cur_val= a;out_char(identifier);break;
  564. case 1:if(a==output_defs_flag)output_defs();
  565. else/*34:*/
  566. #line 420 "ctangle.w"
  567.  
  568. {
  569. a-= 024000;
  570. if((a+name_dir)->equiv!=(char*)text_info)push_level(a+name_dir);
  571. else if(a!=0){
  572. printf("\n! Not present: <");
  573. print_section_name(a+name_dir);err_print(">");
  574.  
  575. }
  576. goto restart;
  577. }
  578.  
  579. /*:34*/
  580. #line 409 "ctangle.w"
  581. ;
  582. break;
  583. default:cur_val= a-050000;if(cur_val>0)cur_section= cur_val;
  584. out_char(section_number);
  585. }
  586. }
  587. }
  588.  
  589. /*:33*//*37:*/
  590. #line 475 "ctangle.w"
  591.  
  592. void
  593. flush_buffer()
  594. {
  595. C_putc('\n');
  596. if(cur_line%100==0&&show_progress){
  597. printf(".");
  598. if(cur_line%500==0)printf("%d",cur_line);
  599. update_terminal;
  600. }
  601. cur_line++;
  602. }
  603.  
  604. /*:37*//*42:*/
  605. #line 529 "ctangle.w"
  606.  
  607. void
  608. phase_two(){
  609. web_file_open= 0;
  610. cur_line= 1;
  611. /*29:*/
  612. #line 322 "ctangle.w"
  613.  
  614. stack_ptr= stack+1;cur_name= name_dir;cur_repl= text_info->text_link+text_info;
  615. cur_byte= cur_repl->tok_start;cur_end= (cur_repl+1)->tok_start;cur_section= 0;
  616.  
  617. /*:29*/
  618. #line 534 "ctangle.w"
  619. ;
  620. /*44:*/
  621. #line 588 "ctangle.w"
  622.  
  623. if(!output_defs_seen)
  624. output_defs();
  625.  
  626. /*:44*/
  627. #line 535 "ctangle.w"
  628. ;
  629. if(text_info->text_link==0&&cur_out_file==end_output_files){
  630. printf("\n! No program text was specified.");mark_harmless;
  631.  
  632. }
  633. else{
  634. if(cur_out_file==end_output_files){
  635. if(show_progress)
  636. printf("\nWriting the output file (%s):",C_file_name);
  637. }
  638. else{
  639. if(show_progress){
  640. printf("\nWriting the output files:");
  641.  
  642. printf(" (%s)",C_file_name);
  643. update_terminal;
  644. }
  645. if(text_info->text_link==0)goto writeloop;
  646. }
  647. while(stack_ptr>stack)get_output();
  648. flush_buffer();
  649. writeloop:/*43:*/
  650. #line 565 "ctangle.w"
  651.  
  652. for(an_output_file= end_output_files;an_output_file>cur_out_file;){
  653. an_output_file--;
  654. sprint_section_name(output_file_name,*an_output_file);
  655. fclose(C_file);
  656. C_file= fopen(output_file_name,"w");
  657. if(C_file==0)fatal("! Cannot open output file:",output_file_name);
  658.  
  659. printf("\n(%s)",output_file_name);update_terminal;
  660. cur_line= 1;
  661. stack_ptr= stack+1;
  662. cur_name= (*an_output_file);
  663. cur_repl= (text_pointer)cur_name->equiv;
  664. cur_byte= cur_repl->tok_start;
  665. cur_end= (cur_repl+1)->tok_start;
  666. while(stack_ptr>stack)get_output();
  667. flush_buffer();
  668. }
  669.  
  670. /*:43*/
  671. #line 556 "ctangle.w"
  672. ;
  673. if(show_happiness)printf("\nDone.");
  674. }
  675. }
  676.  
  677. /*:42*//*47:*/
  678. #line 598 "ctangle.w"
  679.  
  680. void
  681. output_defs()
  682. {
  683. sixteen_bits a;
  684. push_level(NULL);
  685. for(cur_text= text_info+1;cur_text<text_ptr;cur_text++)
  686. if(cur_text->text_link==0){
  687. cur_byte= cur_text->tok_start;
  688. cur_end= (cur_text+1)->tok_start;
  689. C_printf("%s","#define ");
  690. out_state= normal;
  691. protect= 1;
  692. while(cur_byte<cur_end){
  693. a= *cur_byte++;
  694. if(cur_byte==cur_end&&a=='\n')break;
  695. if(out_state==verbatim&&a!=string&&a!=constant&&a!='\n')
  696. C_putc(a);
  697.  
  698. else if(a<0200)out_char(a);
  699. else{
  700. a= (a-0200)*0400+*cur_byte++;
  701. if(a<024000){
  702. cur_val= a;out_char(identifier);
  703. }
  704. else if(a<050000){confusion("macro defs have strange char");}
  705. else{
  706. cur_val= a-050000;cur_section= cur_val;out_char(section_number);
  707. }
  708.  
  709. }
  710. }
  711. protect= 0;
  712. flush_buffer();
  713. }
  714. pop_level(0);
  715. }
  716.  
  717. /*:47*//*49:*/
  718. #line 644 "ctangle.w"
  719.  
  720. void
  721. out_char(cur_char)
  722. eight_bits cur_char;
  723. {
  724. char*j,*k;
  725. restart:
  726. switch(cur_char){
  727. case'\n':if(protect)C_putc(' ');
  728. if(protect||out_state==verbatim)C_putc('\\');
  729. flush_buffer();if(out_state!=verbatim)out_state= normal;break;
  730. /*53:*/
  731. #line 708 "ctangle.w"
  732.  
  733. case identifier:
  734. if(out_state==num_or_id)C_putc(' ');
  735. j= (cur_val+name_dir)->byte_start;
  736. k= (cur_val+name_dir+1)->byte_start;
  737. while(j<k){
  738. if((unsigned char)(*j)<0200)C_putc(*j);
  739.  
  740. else C_printf("%s",translit[(unsigned char)(*j)-0200]);
  741. j++;
  742. }
  743. out_state= num_or_id;break;
  744.  
  745. /*:53*/
  746. #line 655 "ctangle.w"
  747. ;
  748. /*54:*/
  749. #line 721 "ctangle.w"
  750.  
  751. case section_number:
  752. if(cur_val>0)C_printf("/*%d:*/",cur_val);
  753. else if(cur_val<0)C_printf("/*:%d*/",-cur_val);
  754. else if(protect){
  755. cur_byte+= 4;
  756. cur_char= '\n';
  757. goto restart;
  758. }else{
  759. sixteen_bits a;
  760. a= 0400**cur_byte++;
  761. a+= *cur_byte++;
  762. C_printf("\n#line %d \"",a);
  763.  
  764. cur_val= *cur_byte++;
  765. cur_val= 0400*(cur_val-0200)+*cur_byte++;
  766. for(j= (cur_val+name_dir)->byte_start,k= (cur_val+name_dir+1)->byte_start;
  767. j<k;j++)C_putc(*j);
  768. C_printf("%s","\"\n");
  769. }
  770. break;
  771.  
  772. /*:54*/
  773. #line 656 "ctangle.w"
  774. ;
  775. /*50:*/
  776. #line 670 "ctangle.w"
  777.  
  778. case plus_plus:C_putc('+');C_putc('+');out_state= normal;break;
  779. case minus_minus:C_putc('-');C_putc('-');out_state= normal;break;
  780. case minus_gt:C_putc('-');C_putc('>');out_state= normal;break;
  781. case gt_gt:C_putc('>');C_putc('>');out_state= normal;break;
  782. case eq_eq:C_putc('=');C_putc('=');out_state= normal;break;
  783. case lt_lt:C_putc('<');C_putc('<');out_state= normal;break;
  784. case gt_eq:C_putc('>');C_putc('=');out_state= normal;break;
  785. case lt_eq:C_putc('<');C_putc('=');out_state= normal;break;
  786. case not_eq:C_putc('!');C_putc('=');out_state= normal;break;
  787. case and_and:C_putc('&');C_putc('&');out_state= normal;break;
  788. case or_or:C_putc('|');C_putc('|');out_state= normal;break;
  789. case dot_dot_dot:C_putc('.');C_putc('.');C_putc('.');out_state= normal;
  790. break;
  791. case colon_colon:C_putc(':');C_putc(':');out_state= normal;break;
  792. case period_ast:C_putc('.');C_putc('*');out_state= normal;break;
  793. case minus_gt_ast:C_putc('-');C_putc('>');C_putc('*');out_state= normal;
  794. break;
  795.  
  796. /*:50*/
  797. #line 657 "ctangle.w"
  798. ;
  799. case'=':C_putc('=');C_putc(' ');out_state= normal;break;
  800. case join:out_state= unbreakable;break;
  801. case constant:if(out_state==verbatim){
  802. out_state= num_or_id;break;
  803. }
  804. if(out_state==num_or_id)C_putc(' ');out_state= verbatim;break;
  805. case string:if(out_state==verbatim)out_state= normal;
  806. else out_state= verbatim;break;
  807. default:C_putc(cur_char);out_state= normal;break;
  808. }
  809. }
  810.  
  811. /*:49*//*58:*/
  812. #line 799 "ctangle.w"
  813.  
  814. eight_bits
  815. skip_ahead()
  816. {
  817. eight_bits c;
  818. while(1){
  819. if(loc>limit&&(get_line()==0))return(new_section);
  820. *(limit+1)= '@';
  821. while(*loc!='@')loc++;
  822. if(loc<=limit){
  823. loc++;c= ccode[(eight_bits)*loc];loc++;
  824. if(c!=ignore||*(loc-1)=='>')return(c);
  825. }
  826. }
  827. }
  828.  
  829. /*:58*//*60:*/
  830. #line 834 "ctangle.w"
  831.  
  832. int skip_comment(is_long_comment)
  833. boolean is_long_comment;
  834. {
  835. char c;
  836. while(1){
  837. if(loc>limit){
  838. if(is_long_comment){
  839. if(get_line())return(comment_continues= 1);
  840. else{
  841. err_print("! Input ended in mid-comment");
  842.  
  843. return(comment_continues= 0);
  844. }
  845. }
  846. else return(comment_continues= 0);
  847. }
  848. c= *(loc++);
  849. if(is_long_comment&&c=='*'&&*loc=='/'){
  850. loc++;return(comment_continues= 0);
  851. }
  852. if(c=='@'){
  853. if(ccode[(eight_bits)*loc]==new_section){
  854. err_print("! Section name ended in mid-comment");loc--;
  855.  
  856. return(comment_continues= 0);
  857. }
  858. else loc++;
  859. }
  860. }
  861. }
  862.  
  863. /*:60*//*63:*/
  864. #line 884 "ctangle.w"
  865.  
  866. eight_bits
  867. get_next()
  868. {
  869. static int preprocessing= 0;
  870. eight_bits c;
  871. while(1){
  872. if(loc>limit){
  873. if(preprocessing&&*(limit-1)!='\\')preprocessing= 0;
  874. if(get_line()==0)return(new_section);
  875. else if(print_where){
  876. print_where= 0;
  877. /*77:*/
  878. #line 1207 "ctangle.w"
  879.  
  880. store_two_bytes(0150000);
  881. if(changing)id_first= change_file_name;
  882. else id_first= cur_file_name;
  883. id_loc= id_first+strlen(id_first);
  884. if(changing)store_two_bytes((sixteen_bits)change_line);
  885. else store_two_bytes((sixteen_bits)cur_line);
  886. {int a= id_lookup(id_first,id_loc)-name_dir;app_repl((a/0400)+0200);
  887. app_repl(a%0400);}
  888.  
  889. /*:77*/
  890. #line 896 "ctangle.w"
  891. ;
  892. }
  893. else return('\n');
  894. }
  895. c= *loc;
  896. if(comment_continues||(c=='/'&&(*(loc+1)=='*'||*(loc+1)=='/'))){
  897. skip_comment(comment_continues||*(loc+1)=='*');
  898.  
  899. if(comment_continues)return('\n');
  900. else continue;
  901. }
  902. loc++;
  903. if(xisdigit(c)||c=='\\'||c=='.')/*66:*/
  904. #line 962 "ctangle.w"
  905. {
  906. id_first= loc-1;
  907. if(*id_first=='.'&&!xisdigit(*loc))goto mistake;
  908. if(*id_first=='\\')while(xisdigit(*loc))loc++;
  909. else{
  910. if(*id_first=='0'){
  911. if(*loc=='x'||*loc=='X'){
  912. loc++;while(xisxdigit(*loc))loc++;goto found;
  913. }
  914. }
  915. while(xisdigit(*loc))loc++;
  916. if(*loc=='.'){
  917. loc++;
  918. while(xisdigit(*loc))loc++;
  919. }
  920. if(*loc=='e'||*loc=='E'){
  921. if(*++loc=='+'||*loc=='-')loc++;
  922. while(xisdigit(*loc))loc++;
  923. }
  924. }
  925. found:while(*loc=='u'||*loc=='U'||*loc=='l'||*loc=='L'
  926. ||*loc=='f'||*loc=='F')loc++;
  927. id_loc= loc;
  928. return(constant);
  929. }
  930.  
  931. /*:66*/
  932. #line 908 "ctangle.w"
  933.  
  934. else if(c=='\''||c=='"'||(c=='L'&&(*loc=='\''||*loc=='"')))
  935. /*67:*/
  936. #line 993 "ctangle.w"
  937. {
  938. char delim= c;
  939. id_first= section_text+1;
  940. id_loc= section_text;*++id_loc= delim;
  941. if(delim=='L'){
  942. delim= *loc++;*++id_loc= delim;
  943. }
  944. while(1){
  945. if(loc>=limit){
  946. if(*(limit-1)!='\\'){
  947. err_print("! String didn't end");loc= limit;break;
  948.  
  949. }
  950. if(get_line()==0){
  951. err_print("! Input ended in middle of string");loc= buffer;break;
  952.  
  953. }
  954. else if(++id_loc<=section_text_end)*id_loc= '\n';
  955.  
  956. }
  957. if((c= *loc++)==delim){
  958. if(++id_loc<=section_text_end)*id_loc= c;
  959. break;
  960. }
  961. if(c=='\\'){
  962. if(loc>=limit)continue;
  963. if(++id_loc<=section_text_end)*id_loc= '\\';
  964. c= *loc++;
  965. }
  966. if(++id_loc<=section_text_end)*id_loc= c;
  967. }
  968. if(id_loc>=section_text_end){
  969. printf("\n! String too long: ");
  970.  
  971. term_write(section_text+1,25);
  972. err_print("...");
  973. }
  974. id_loc++;
  975. return(string);
  976. }
  977.  
  978. /*:67*/
  979. #line 910 "ctangle.w"
  980.  
  981. else if(isalpha(c)||isxalpha(c)||ishigh(c))
  982. /*65:*/
  983. #line 956 "ctangle.w"
  984. {
  985. id_first= --loc;
  986. while(isalpha(*++loc)||isdigit(*loc)||isxalpha(*loc)||ishigh(*loc));
  987. id_loc= loc;return(identifier);
  988. }
  989.  
  990. /*:65*/
  991. #line 912 "ctangle.w"
  992.  
  993. else if(c=='@')/*68:*/
  994. #line 1037 "ctangle.w"
  995. {
  996. c= ccode[(eight_bits)*loc++];
  997. switch(c){
  998. case ignore:continue;
  999. case output_defs_code:output_defs_seen= 1;return(c);
  1000. case translit_code:err_print("! Use @l in limbo only");continue;
  1001.  
  1002. case control_text:while((c= skip_ahead())=='@');
  1003.  
  1004. if(*(loc-1)!='>')
  1005. err_print("! Double @ should be used in control text");
  1006.  
  1007. continue;
  1008. case section_name:
  1009. cur_section_name_char= *(loc-1);
  1010. /*70:*/
  1011. #line 1086 "ctangle.w"
  1012. {
  1013. char*k;
  1014. /*72:*/
  1015. #line 1106 "ctangle.w"
  1016.  
  1017. k= section_text;
  1018. while(1){
  1019. if(loc>limit&&get_line()==0){
  1020. err_print("! Input ended in section name");
  1021.  
  1022. loc= buffer+1;break;
  1023. }
  1024. c= *loc;
  1025. /*73:*/
  1026. #line 1130 "ctangle.w"
  1027.  
  1028. if(c=='@'){
  1029. c= *(loc+1);
  1030. if(c=='>'){
  1031. loc+= 2;break;
  1032. }
  1033. if(ccode[(eight_bits)c]==new_section){
  1034. err_print("! Section name didn't end");break;
  1035.  
  1036. }
  1037. if(ccode[(eight_bits)c]==section_name){
  1038. err_print("! Nesting of section names not allowed");break;
  1039.  
  1040. }
  1041. *(++k)= '@';loc++;
  1042. }
  1043.  
  1044. /*:73*/
  1045. #line 1115 "ctangle.w"
  1046. ;
  1047. loc++;if(k<section_text_end)k++;
  1048. if(xisspace(c)){
  1049. c= ' ';if(*(k-1)==' ')k--;
  1050. }
  1051. *k= c;
  1052. }
  1053. if(k>=section_text_end){
  1054. printf("\n! Section name too long: ");
  1055.  
  1056. term_write(section_text+1,25);
  1057. printf("...");mark_harmless;
  1058. }
  1059. if(*k==' '&&k>section_text)k--;
  1060.  
  1061. /*:72*/
  1062. #line 1088 "ctangle.w"
  1063. ;
  1064. if(k-section_text>3&&strncmp(k-2,"...",3)==0)
  1065. cur_section_name= section_lookup(section_text+1,k-3,1);
  1066. else cur_section_name= section_lookup(section_text+1,k,0);
  1067. if(cur_section_name_char=='(')
  1068. /*40:*/
  1069. #line 510 "ctangle.w"
  1070.  
  1071. {
  1072. if(cur_out_file>output_files){
  1073. for(an_output_file= cur_out_file;
  1074. an_output_file<end_output_files;an_output_file++)
  1075. if(*an_output_file==cur_section_name)break;
  1076. if(an_output_file==end_output_files)
  1077. *--cur_out_file= cur_section_name;
  1078. }else{
  1079. overflow("output files");
  1080. }
  1081. }
  1082.  
  1083. /*:40*/
  1084. #line 1094 "ctangle.w"
  1085. ;
  1086. return(section_name);
  1087. }
  1088.  
  1089. /*:70*/
  1090. #line 1052 "ctangle.w"
  1091. ;
  1092. case string:/*74:*/
  1093. #line 1152 "ctangle.w"
  1094. {
  1095. id_first= loc++;*(limit+1)= '@';*(limit+2)= '>';
  1096. while(*loc!='@'||*(loc+1)!='>')loc++;
  1097. if(loc>=limit)err_print("! Verbatim string didn't end");
  1098.  
  1099. id_loc= loc;loc+= 2;
  1100. return(string);
  1101. }
  1102.  
  1103. /*:74*/
  1104. #line 1053 "ctangle.w"
  1105. ;
  1106. case ord:/*69:*/
  1107. #line 1065 "ctangle.w"
  1108.  
  1109. id_first= loc;
  1110. if(*loc=='\\'){
  1111. if(*++loc=='\'')loc++;
  1112. }
  1113. while(*loc!='\''){
  1114. if(*loc=='@'){
  1115. if(*(loc+1)!='@')
  1116. err_print("! Double @ should be used in ASCII constant");
  1117.  
  1118. else loc++;
  1119. }
  1120. loc++;
  1121. if(loc>limit){
  1122. err_print("! String didn't end");loc= limit-1;break;
  1123.  
  1124. }
  1125. }
  1126. loc++;
  1127. return(ord);
  1128.  
  1129. /*:69*/
  1130. #line 1054 "ctangle.w"
  1131. ;
  1132. default:return(c);
  1133. }
  1134. }
  1135.  
  1136. /*:68*/
  1137. #line 913 "ctangle.w"
  1138.  
  1139. else if(xisspace(c)){
  1140. if(!preprocessing||loc>limit)continue;
  1141.  
  1142. else return(' ');
  1143. }
  1144. else if(c=='#'&&loc==buffer+1)preprocessing= 1;
  1145. mistake:/*64:*/
  1146. #line 934 "ctangle.w"
  1147.  
  1148. switch(c){
  1149. case'+':if(*loc=='+')compress(plus_plus);break;
  1150. case'-':if(*loc=='-'){compress(minus_minus);}
  1151. else if(*loc=='>')if(*(loc+1)=='*'){loc++;compress(minus_gt_ast);}
  1152. else compress(minus_gt);break;
  1153. case'.':if(*loc=='*'){compress(period_ast);}
  1154. else if(*loc=='.'&&*(loc+1)=='.'){
  1155. loc++;compress(dot_dot_dot);
  1156. }
  1157. break;
  1158. case':':if(*loc==':')compress(colon_colon);break;
  1159. case'=':if(*loc=='=')compress(eq_eq);break;
  1160. case'>':if(*loc=='='){compress(gt_eq);}
  1161. else if(*loc=='>')compress(gt_gt);break;
  1162. case'<':if(*loc=='='){compress(lt_eq);}
  1163. else if(*loc=='<')compress(lt_lt);break;
  1164. case'&':if(*loc=='&')compress(and_and);break;
  1165. case'|':if(*loc=='|')compress(or_or);break;
  1166. case'!':if(*loc=='=')compress(not_eq);break;
  1167. }
  1168.  
  1169. /*:64*/
  1170. #line 920 "ctangle.w"
  1171.  
  1172. return(c);
  1173. }
  1174. }
  1175.  
  1176. /*:63*//*76:*/
  1177. #line 1184 "ctangle.w"
  1178.  
  1179. void
  1180. scan_repl(t)
  1181. eight_bits t;
  1182. {
  1183. sixteen_bits a;
  1184. if(t==section_name){/*77:*/
  1185. #line 1207 "ctangle.w"
  1186.  
  1187. store_two_bytes(0150000);
  1188. if(changing)id_first= change_file_name;
  1189. else id_first= cur_file_name;
  1190. id_loc= id_first+strlen(id_first);
  1191. if(changing)store_two_bytes((sixteen_bits)change_line);
  1192. else store_two_bytes((sixteen_bits)cur_line);
  1193. {int a= id_lookup(id_first,id_loc)-name_dir;app_repl((a/0400)+0200);
  1194. app_repl(a%0400);}
  1195.  
  1196. /*:77*/
  1197. #line 1190 "ctangle.w"
  1198. ;}
  1199. while(1)switch(a= get_next()){
  1200. /*78:*/
  1201. #line 1217 "ctangle.w"
  1202.  
  1203. case identifier:a= id_lookup(id_first,id_loc)-name_dir;
  1204. app_repl((a/0400)+0200);
  1205. app_repl(a%0400);break;
  1206. case section_name:if(t!=section_name)goto done;
  1207. else{
  1208. /*79:*/
  1209. #line 1245 "ctangle.w"
  1210. {
  1211. char*try_loc= loc;
  1212. while(*try_loc==' '&&try_loc<limit)try_loc++;
  1213. if(*try_loc=='+'&&try_loc<limit)try_loc++;
  1214. while(*try_loc==' '&&try_loc<limit)try_loc++;
  1215. if(*try_loc=='=')err_print("! Missing `@ ' before a named section");
  1216.  
  1217.  
  1218.  
  1219. }
  1220.  
  1221. /*:79*/
  1222. #line 1223 "ctangle.w"
  1223. ;
  1224. a= cur_section_name-name_dir;
  1225. app_repl((a/0400)+0250);
  1226. app_repl(a%0400);
  1227. /*77:*/
  1228. #line 1207 "ctangle.w"
  1229.  
  1230. store_two_bytes(0150000);
  1231. if(changing)id_first= change_file_name;
  1232. else id_first= cur_file_name;
  1233. id_loc= id_first+strlen(id_first);
  1234. if(changing)store_two_bytes((sixteen_bits)change_line);
  1235. else store_two_bytes((sixteen_bits)cur_line);
  1236. {int a= id_lookup(id_first,id_loc)-name_dir;app_repl((a/0400)+0200);
  1237. app_repl(a%0400);}
  1238.  
  1239. /*:77*/
  1240. #line 1227 "ctangle.w"
  1241. ;break;
  1242. }
  1243. case output_defs_code:
  1244. a= output_defs_flag;
  1245. app_repl((a/0400)+0200);
  1246. app_repl(a%0400);
  1247. /*77:*/
  1248. #line 1207 "ctangle.w"
  1249.  
  1250. store_two_bytes(0150000);
  1251. if(changing)id_first= change_file_name;
  1252. else id_first= cur_file_name;
  1253. id_loc= id_first+strlen(id_first);
  1254. if(changing)store_two_bytes((sixteen_bits)change_line);
  1255. else store_two_bytes((sixteen_bits)cur_line);
  1256. {int a= id_lookup(id_first,id_loc)-name_dir;app_repl((a/0400)+0200);
  1257. app_repl(a%0400);}
  1258.  
  1259. /*:77*/
  1260. #line 1233 "ctangle.w"
  1261. ;break;
  1262. case constant:case string:
  1263. /*80:*/
  1264. #line 1256 "ctangle.w"
  1265.  
  1266. app_repl(a);
  1267. while(id_first<id_loc){
  1268. if(*id_first=='@'){
  1269. if(*(id_first+1)=='@')id_first++;
  1270. else err_print("! Double @ should be used in string");
  1271.  
  1272. }
  1273. app_repl(*id_first++);
  1274. }
  1275. app_repl(a);break;
  1276.  
  1277. /*:80*/
  1278. #line 1235 "ctangle.w"
  1279. ;
  1280. case ord:
  1281. /*81:*/
  1282. #line 1272 "ctangle.w"
  1283. {
  1284. int c= (eight_bits)*id_first;
  1285. if(c=='\\'){
  1286. c= *++id_first;
  1287. if(c>='0'&&c<='7'){
  1288. c-= '0';
  1289. if(*(id_first+1)>='0'&&*(id_first+1)<='7'){
  1290. c= 8*c+*(++id_first)-'0';
  1291. if(*(id_first+1)>='0'&&*(id_first+1)<='7'&&c<32)
  1292. c= 8*c+*(++id_first)-'0';
  1293. }
  1294. }
  1295. else switch(c){
  1296. case't':c= '\t';break;
  1297. case'n':c= '\n';break;
  1298. case'b':c= '\b';break;
  1299. case'f':c= '\f';break;
  1300. case'v':c= '\v';break;
  1301. case'r':c= '\r';break;
  1302. case'a':c= '\7';break;
  1303. case'?':c= '?';break;
  1304. case'x':
  1305. if(xisdigit(*(id_first+1)))c= *(++id_first)-'0';
  1306. else if(xisxdigit(*(id_first+1))){
  1307. ++id_first;
  1308. c= toupper(*id_first)-'A'+10;
  1309. }
  1310. if(xisdigit(*(id_first+1)))c= 16*c+*(++id_first)-'0';
  1311. else if(xisxdigit(*(id_first+1))){
  1312. ++id_first;
  1313. c= 16*c+toupper(*id_first)-'A'+10;
  1314. }
  1315. break;
  1316. case'\\':c= '\\';break;
  1317. case'\'':c= '\'';break;
  1318. case'\"':c= '\"';break;
  1319. default:err_print("! Unrecognized escape sequence");
  1320.  
  1321. }
  1322. }
  1323.  
  1324. app_repl(constant);
  1325. if(c>=100)app_repl('0'+c/100);
  1326. if(c>=10)app_repl('0'+(c/10)%10);
  1327. app_repl('0'+c%10);
  1328. app_repl(constant);
  1329. }
  1330. break;
  1331.  
  1332. /*:81*/
  1333. #line 1237 "ctangle.w"
  1334. ;
  1335. case definition:case format_code:case begin_C:if(t!=section_name)goto done;
  1336. else{
  1337. err_print("! @d, @f and @c are ignored in C text");continue;
  1338.  
  1339. }
  1340. case new_section:goto done;
  1341.  
  1342. /*:78*/
  1343. #line 1195 "ctangle.w"
  1344.  
  1345. default:app_repl(a);
  1346. }
  1347. done:next_control= (eight_bits)a;
  1348. if(text_ptr>text_info_end)overflow("text");
  1349. cur_text= text_ptr;(++text_ptr)->tok_start= tok_ptr;
  1350. }
  1351.  
  1352. /*:76*//*83:*/
  1353. #line 1334 "ctangle.w"
  1354.  
  1355. void
  1356. scan_section()
  1357. {
  1358. name_pointer p;
  1359. text_pointer q;
  1360. sixteen_bits a;
  1361. section_count++;
  1362. if(*(loc-1)=='*'&&show_progress){
  1363. printf("*%d",section_count);update_terminal;
  1364. }
  1365. next_control= 0;
  1366. while(1){
  1367. /*84:*/
  1368. #line 1372 "ctangle.w"
  1369.  
  1370. while(next_control<definition)
  1371.  
  1372. if((next_control= skip_ahead())==section_name){
  1373. loc-= 2;next_control= get_next();
  1374. }
  1375.  
  1376. /*:84*/
  1377. #line 1348 "ctangle.w"
  1378. ;
  1379. if(next_control==definition){
  1380. /*85:*/
  1381. #line 1379 "ctangle.w"
  1382. {
  1383. while((next_control= get_next())=='\n');
  1384. if(next_control!=identifier){
  1385. err_print("! Definition flushed, must start with identifier");
  1386.  
  1387. continue;
  1388. }
  1389. app_repl(((a= id_lookup(id_first,id_loc)-name_dir)/0400)+0200);
  1390.  
  1391. app_repl(a%0400);
  1392. if(*loc!='('){
  1393. app_repl(string);app_repl(' ');app_repl(string);
  1394. }
  1395. print_where= 0;scan_repl(macro);
  1396. cur_text->text_link= 0;
  1397. }
  1398.  
  1399. /*:85*/
  1400. #line 1350 "ctangle.w"
  1401.  
  1402. continue;
  1403. }
  1404. if(next_control==begin_C){
  1405. p= name_dir;break;
  1406. }
  1407. if(next_control==section_name){
  1408. p= cur_section_name;
  1409. /*86:*/
  1410. #line 1404 "ctangle.w"
  1411.  
  1412. while((next_control= get_next())=='+');
  1413. if(next_control!='='&&next_control!=eq_eq)
  1414. continue;
  1415.  
  1416. /*:86*/
  1417. #line 1358 "ctangle.w"
  1418. ;
  1419. break;
  1420. }
  1421. return;
  1422. }
  1423. /*87:*/
  1424. #line 1409 "ctangle.w"
  1425.  
  1426. /*88:*/
  1427. #line 1414 "ctangle.w"
  1428.  
  1429. store_two_bytes((sixteen_bits)(0150000+section_count));
  1430.  
  1431.  
  1432. /*:88*/
  1433. #line 1410 "ctangle.w"
  1434. ;
  1435. scan_repl(section_name);
  1436. /*89:*/
  1437. #line 1418 "ctangle.w"
  1438.  
  1439. if(p==name_dir||p==0){
  1440. (last_unnamed)->text_link= cur_text-text_info;last_unnamed= cur_text;
  1441. }
  1442. else if(p->equiv==(char*)text_info)p->equiv= (char*)cur_text;
  1443.  
  1444. else{
  1445. q= (text_pointer)p->equiv;
  1446. while(q->text_link<section_flag)
  1447. q= q->text_link+text_info;
  1448. q->text_link= cur_text-text_info;
  1449. }
  1450. cur_text->text_link= section_flag;
  1451.  
  1452.  
  1453. /*:89*/
  1454. #line 1412 "ctangle.w"
  1455. ;
  1456.  
  1457. /*:87*/
  1458. #line 1363 "ctangle.w"
  1459. ;
  1460. }
  1461.  
  1462. /*:83*//*91:*/
  1463. #line 1436 "ctangle.w"
  1464.  
  1465. void
  1466. phase_one(){
  1467. phase= 1;
  1468. section_count= 0;
  1469. reset_input();
  1470. skip_limbo();
  1471. while(!input_has_ended)scan_section();
  1472. check_complete();
  1473. phase= 2;
  1474. }
  1475.  
  1476. /*:91*//*93:*/
  1477. #line 1454 "ctangle.w"
  1478.  
  1479. void
  1480. skip_limbo()
  1481. {
  1482. char c;
  1483. while(1){
  1484. if(loc>limit&&get_line()==0)return;
  1485. *(limit+1)= '@';
  1486. while(*loc!='@')loc++;
  1487. if(loc++<=limit){
  1488. c= *loc++;
  1489. if(ccode[(eight_bits)c]==new_section)break;
  1490. switch(ccode[(eight_bits)c]){
  1491. case translit_code:/*94:*/
  1492. #line 1483 "ctangle.w"
  1493.  
  1494. while(xisspace(*loc)&&loc<limit)loc++;
  1495. loc+= 3;
  1496. if(loc>limit||!xisxdigit(*(loc-3))||!xisxdigit(*(loc-2))
  1497. ||(*(loc-3)>='0'&&*(loc-3)<='7')||!xisspace(*(loc-1)))
  1498. err_print("! Improper hex number following @l");
  1499.  
  1500. else{
  1501. unsigned i;
  1502. char*beg;
  1503. sscanf(loc-3,"%x",&i);
  1504. while(xisspace(*loc)&&loc<limit)loc++;
  1505. beg= loc;
  1506. while(loc<limit&&(xisalpha(*loc)||xisdigit(*loc)||*loc=='_'))loc++;
  1507. if(loc-beg>=translit_length)
  1508. err_print("! Replacement string in @l too long");
  1509.  
  1510. else{
  1511. strncpy(translit[i-0200],beg,loc-beg);
  1512. translit[i-0200][loc-beg]= '\0';
  1513. }
  1514. }
  1515.  
  1516. /*:94*/
  1517. #line 1467 "ctangle.w"
  1518. ;break;
  1519. case format_code:case'@':break;
  1520. case control_text:if(c=='q'||c=='Q'){
  1521. while((c= skip_ahead())=='@');
  1522. if(*(loc-1)!='>')
  1523. err_print("! Double @ should be used in control text");
  1524.  
  1525. break;
  1526. }
  1527. default:err_print("! Double @ should be used in limbo");
  1528.  
  1529. }
  1530. }
  1531. }
  1532. }
  1533.  
  1534. /*:93*//*95:*/
  1535. #line 1509 "ctangle.w"
  1536.  
  1537. void
  1538. print_stats(){
  1539. printf("\nMemory usage statistics:\n");
  1540. printf("%ld names (out of %ld)\n",
  1541. (long)(name_ptr-name_dir),(long)max_names);
  1542. printf("%ld replacement texts (out of %ld)\n",
  1543. (long)(text_ptr-text_info),(long)max_texts);
  1544. printf("%ld bytes (out of %ld)\n",
  1545. (long)(byte_ptr-byte_mem),(long)max_bytes);
  1546. printf("%ld tokens (out of %ld)\n",
  1547. (long)(tok_ptr-tok_mem),(long)max_toks);
  1548. }
  1549.  
  1550. /*:95*/
  1551.